package com.example.fw;


import java.util.LinkedList;
import java.util.List;

public class FolderList {
    private List<String> folderNames = null;

    public FolderList (List<String> folderNames){
        this.folderNames = new LinkedList<String>(folderNames);
    }

    public int size(){
        if (folderNames == null){
            return 0;
        }
        else{
            return folderNames.size();
        }
    }

    public String get(int index){
        return folderNames.get(index);
    }

    public FolderList withAdded(String folderName) {
        FolderList resultList = new FolderList(folderNames);
        resultList.folderNames.add(folderName);
        return resultList;
    }

    public FolderList withRemoved(int folderIndex) {
        FolderList resultList = new FolderList(folderNames);
        resultList.folderNames.remove(folderIndex);
        return resultList;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        FolderList that = (FolderList) o;

        if (folderNames != null ? !folderNames.equals(that.folderNames) : that.folderNames != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return folderNames != null ? folderNames.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "FolderList{" +
                folderNames +
                '}';
    }
}
